const { resolve } = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

module.exports = {
  mode: "development",
  entry: resolve(__dirname, 'src/index.ts'),
  output: {
    filename: "index.handle.js",
    path: resolve(__dirname, 'dist')
  },
  resolve: {
    extensions: ['.ts', '.tsc', '.js']
  },
  module: {
    rules: [{
      test: /\.ts?$/,
      use: 'ts-loader',
      exclude: /node_modules/
    }]
  },
  plugins: [
    new CleanWebpackPlugin({
      cleanStaleWebpackAssets: false
    }),
    new HtmlWebpackPlugin({
      template: "src/template/index.html"
    })
  ],
  devtool: process.env.NODE_ENV === 'production' ? 'source-map' : 'inline-source-map',
  devServer: {
    contentBase: './dist',
    port: 3000,
    open: true,
    compress: true
  }
}